package lovo.practice_7_14;

import com.sun.tools.javac.Main;
import lovo.FileUtil.FileUtil;
import lovo.Util.Util;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class SavePanel extends JPanel implements ActionListener {
    private JButton jButtonSave;
    private JTextField jTextFieldSave;
    private J189_7_14 frame;
    private Icon imgback = Util.getimagesIcon("/Images/buttonOff.jpg");
    private JButton jButtonBack;
    private Icon ImageSave = Util.getimagesIcon("/Images/buttonSave.jpg");

    public SavePanel(J189_7_14 frame) {
        this.frame = frame;
        this.setLayout(null);
        this.setOpaque(false);
        jButtonSave = new JButton(ImageSave);
        jButtonSave.setBounds(200, 200, 140, 50);
        this.add(jButtonSave);

        jTextFieldSave = new JTextField();
        jTextFieldSave.setBounds(400, 200, 140, 50);
        this.add(jTextFieldSave);


        jButtonBack = new JButton(imgback);
        jButtonBack.setBounds(500, 400, 140, 50);
        this.add(jButtonBack);
        jButtonBack.addActionListener(this);
        jButtonSave.addActionListener(this);

    }


    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == jButtonBack) {
            frame.switchPanel("mune");
        } else if (e.getSource() == jButtonSave) {
            frame.getUsers().setBalance(frame.getUsers().getBalance() + Integer.parseInt(this.jTextFieldSave.getText()));

            frame.update();

            JOptionPane.showMessageDialog(this, "存款成功");
            frame.getSavePanel().jTextFieldSave.setText("");
        }
    }


}
